/**
 * 
 *
 * 
 *
 * 
 */

package com.person.modules.person.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.person.common.utils.Constant;
import com.person.common.utils.PageUtils;
import com.person.common.utils.Query;
import com.person.modules.person.dao.InterviewPlanDao;
import com.person.modules.person.entity.InterviewPlanEntity;
import com.person.modules.person.entity.SalaryRecordEntity;
import com.person.modules.person.entity.UserDocEntity;
import com.person.modules.person.service.InterviewPlanService;
import com.person.modules.sys.entity.SysUserEntity;
import com.person.modules.sys.service.SysUserService;
import com.person.modules.sys.shiro.ShiroUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
/*//ge表示大于等于、gt表示大于、le表示小于等于、lt表示小于
        //eq等于、ne不等于
        //between
        //查询年龄20-30范围 1.代表字段  2.代表开始值  3.代表结束值
        queryWrapper.between("age",20,30);
        //like模糊查询
        queryWrapper.like("username","吸");
        //orderByDesc 降序  ASC升序
        queryWrapper.orderByDesc("id");
        //last sql语句最后拼接
        queryWrapper.last("limit 1");
        //查询指定的列
        queryWrapper.select("id","name");*/

@Service("interviewPlanService")
public class InterviewPlanServiceImpl extends ServiceImpl<InterviewPlanDao, InterviewPlanEntity> implements InterviewPlanService {
    @Autowired
    SysUserService userService;



    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String candidate = (String)params.get("candidate");
        String candidateMobile = (String)params.get("candidateMobile");
        IPage<InterviewPlanEntity> page = this.page(
                new Query<InterviewPlanEntity>().getPage(params),
                new QueryWrapper<InterviewPlanEntity>()
                        .like(StringUtils.isNotBlank(candidate), "candidate", candidate)
                        .like(StringUtils.isNotBlank(candidateMobile), "candidate_mobile", candidateMobile)
                        .apply(params.get(Constant.SQL_FILTER) != null, (String)params.get(Constant.SQL_FILTER))
        );
        List<InterviewPlanEntity> records = page.getRecords();

        List<InterviewPlanEntity> list = new ArrayList<InterviewPlanEntity>();
        for (InterviewPlanEntity r : records) {
            r.setMeetName(userService.getById(r.getMeetUserId()).getName());
            list.add(r);
        }
        page.setRecords(list);
        return new PageUtils(page);
    }

    @Override
    public void deleteBatch(Long[] ids) {
        this.removeByIds(Arrays.asList(ids));

    }

    @Override
    public void update(InterviewPlanEntity record) {
        this.updateById(record);
    }

    @Override
    public PageUtils selectName(Map<String, Object> params) {
        /*//创建对象
        QueryWrapper<InterviewPlanEntity> queryWrapper = new QueryWrapper<>();
        //通过queryWrapper设置条件
        //查询id>=30记录
        //第一个参数字段名称，第二个参数设置值
        queryWrapper.eq("meetName",meetNmae);
        List<InterviewPlanEntity> interviewPlanEntities = this.baseMapper.selectList(queryWrapper);*/

        IPage<InterviewPlanEntity> page = this.page(
                new Query<InterviewPlanEntity>().getPage(params),
                new QueryWrapper<InterviewPlanEntity>().eq("meet_user_id", ShiroUtils.getUserEntity().getUserId())
                        .apply(params.get(Constant.SQL_FILTER) != null, (String)params.get(Constant.SQL_FILTER))
        );
        List<InterviewPlanEntity> recordss = page.getRecords();

        List<InterviewPlanEntity> list = new ArrayList<InterviewPlanEntity>();
        for (InterviewPlanEntity r : recordss) {
            r.setMeetName(userService.getById(r.getMeetUserId()).getName());
            list.add(r);
        }
        page.setRecords(list);
        return new PageUtils(page);

    }
}
